#
# rule.mk
# from Makefile template for multi-directory
#

.PHONY: _depend

_depend: $(obj).depend

$(obj).depend: $(SRCTREE)/config.mk Makefile $(SRC_C) $(SRC_CPP)
	@rm -f $@
	@for f in $(SRC_C); do \
	        g=`echo $$f | sed -e 's/\(.*\)\.\w/\1.o/'`; \
	        $(CC) -MM $(CFLAGS) -E -MQ $(obj)$$g $$f >> $@ ; \
	done
	@for f in $(SRC_CPP); do \
	        g=`echo $$f | sed -e 's/\(.*\)\...\w/\1.o/'`; \
	        $(CXX) -MM $(CFLAGS) -E -MQ $(obj)$$g $$f >> $@ ; \
	done

# make all .c or .cpp
$(obj)%.o: %.c
	@echo "	[CC]:  " $(addsuffix .c, $(basename $(notdir $@)))
	@$(CC) $(CFLAGS) -c $< -o $@

$(obj)%.o: %.cpp
	@echo "	[CXX]: " $(addsuffix .cpp, $(basename $(notdir $@)))
	@$(CXX) $(CFLAGS) -c $< -o $@

$(LIB): $(OBJ_C) $(OBJ_CPP)
	@echo "	[AR]:  " $(notdir $@)
	@$(AR) $(ARFLAGS) $@ $^
